package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Ra;
import com.example.entity.PsLogs;
import com.example.entity.PsUser;
import com.example.mapper.PsLogsMapper;
import com.example.service.PsLogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author s
 * @since 2024-04-28
 */
@CrossOrigin(origins="*")
@RestController
@RequestMapping("/ps-logs")
public class PsLogsController {

    @Autowired
    private PsLogsService psLogsService;

    @Autowired
    private PsLogsMapper psLogsMapper;
    /**
     * 分页查询log日志数据
     * @param nowPage
     * @param psLogs
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectPage")
    public Ra selectPage(Integer nowPage, PsLogs psLogs) {
        if(nowPage==null) {
            nowPage = 1;
        }
        IPage<PsLogs> page = new Page<>(nowPage, 3);
        QueryWrapper<PsLogs> psUserQueryWrapper = new QueryWrapper<PsLogs>();
        List<PsLogs> psLogss=psLogsMapper.selectList(psUserQueryWrapper);
        System.out.println("=="+psLogs.toString()+"==");
        if(psLogs.getOperatedatetime()!=null ) {
            psUserQueryWrapper.eq("operateDatetime",psLogs.getOperatedatetime());
        }
        IPage<PsLogs> psLogsIPage = psLogsMapper.selectPage(page, psUserQueryWrapper);
        List<PsLogs> records = psLogsIPage.getRecords();
        long count = psLogsService.count();
        return new Ra().AddDatamap("Logs",records).AddDatamap("count",count);
    }



}
